package com.ruoyi.oos.web.controller.overrun;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.util.StringUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.oos.duty.domain.DutyClasses;
import com.ruoyi.oos.duty.mapper.DutyClassesMapper;
import com.ruoyi.oos.overrun.service.IOverrunRecordCalService;

@Controller
@RequestMapping("/overrun/cal")
public class OverturnRecordCalAction extends BaseController {
	
	 private String prefix = "overrun/record";
	
	 @Autowired
	 IOverrunRecordCalService overrunRecordCalService;
	
	 @Autowired
	 DutyClassesMapper classesMapper;
	 
	 @GetMapping()
	 public String calData() {
		// overrunRecordCalService.calOverrunRecord(DateUtils.addDays(new Date(), -1));
		   return prefix + "/calData";
	 }
	 //
	 @RequestMapping(value="calDataJson",method=RequestMethod.POST)
	 @ResponseBody
	 public String calDataJson( String startTime, String endTime) {
		 if(StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
			 return "-1";
		 }
		 DutyClasses classes = new DutyClasses();
		 classes.setDutyId(1);
		List<DutyClasses> clasesList = classesMapper.selectDutyClassesList(classes);
		 List<String> list = DateUtils.getDays(startTime, endTime);
		 for (String date : list) {
			for (DutyClasses model : clasesList) {
				String time = model.getTime();
				String curDate = date+" "+time;
				Date curDate1 =DateUtils.parseDate(curDate);
				 overrunRecordCalService.calOverrunRecord(DateUtils.addMinutes(curDate1, 1),1L);
			}
		}
		 return "success";
	 }
	 
	 
	 public String testCalTask() {
		 System.out.println("nihao. 我今年8岁了");
		 return null;
	 }
	 

}
